package com.fc.test.service;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.Convert;
import com.fc.test.mapper.auto.TAbbGonggaoMapper;
import com.fc.test.model.auto.TAbbGonggao;
import com.fc.test.model.auto.TAbbGonggaoExample;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;

/**
 * Service
* @Title: TAbbGonggaoService.java 
* @Package com.fc.test.entity 
* @author fuce
* @email 87766867@qq.com
* @date 2019-08-13 08:52:44  
 */
@Service
public class TAbbGonggaoService implements BaseService<TAbbGonggao, TAbbGonggaoExample>{
	@Autowired
	private TAbbGonggaoMapper tAbbGonggaoMapper;

	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<TAbbGonggao> list(Tablepar tablepar){
	        TAbbGonggaoExample testExample=new TAbbGonggaoExample();
	        testExample.setOrderByClause("id ASC");
	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<TAbbGonggao> list= tAbbGonggaoMapper.selectByExample(testExample);
	        PageInfo<TAbbGonggao> pageInfo = new PageInfo<TAbbGonggao>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
		List<String> lista=Convert.toListStrArray(ids);
		TAbbGonggaoExample example=new TAbbGonggaoExample();
		example.createCriteria().andIdIn(lista);
		return tAbbGonggaoMapper.deleteByExample(example);
	}


	@Override
	public TAbbGonggao selectByPrimaryKey(String id) {

		return tAbbGonggaoMapper.selectByPrimaryKey(id);
	}


	@Override
	public int updateByPrimaryKeySelective(TAbbGonggao record) {
		record.setReadNum(0);
		return tAbbGonggaoMapper.updateByPrimaryKeySelective(record);
	}

	/**
	 * 添加
	 */
	@Override
	public int insertSelective(TAbbGonggao record) {
		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());
		return tAbbGonggaoMapper.insertSelective(record);
	}










	@Override
	public int updateByExampleSelective(TAbbGonggao record, TAbbGonggaoExample example) {

		return tAbbGonggaoMapper.updateByExampleSelective(record, example);
	}


	@Override
	public int updateByExample(TAbbGonggao record, TAbbGonggaoExample example) {

		return tAbbGonggaoMapper.updateByExample(record, example);
	}

	@Override
	public List<TAbbGonggao> selectByExample(TAbbGonggaoExample example) {

		return tAbbGonggaoMapper.selectByExample(example);
	}


	@Override
	public long countByExample(TAbbGonggaoExample example) {

		return tAbbGonggaoMapper.countByExample(example);
	}


	@Override
	public int deleteByExample(TAbbGonggaoExample example) {

		return tAbbGonggaoMapper.deleteByExample(example);
	}

	public List<TAbbGonggao> getIndexGonggao(){
		return tAbbGonggaoMapper.getIndexGonggao();
	}

	public TAbbGonggao getGonggaoDetail(String id){
		TAbbGonggao tAbbGonggao = tAbbGonggaoMapper.selectByPrimaryKey(id);
		int readNum = tAbbGonggao.getReadNum();
		tAbbGonggao.setReadNum(readNum+1);
		tAbbGonggaoMapper.updateByPrimaryKey(tAbbGonggao);
		return tAbbGonggao;
	}



}
